#include<bits/stdc++.h>
using namespace std;
#define int long long

int days[] = {0, 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31};

signed main() {
	int y, m, d;
	scanf("%lld-%lld-%lld", &y, &m, &d);
	int a, b, z;
	scanf("%lld%lld%lld", &a, &b, &z);

	int sum = 0, target;
	for (int i = 0; i <= 10000000; i++) {
		if (i % 3)
			sum += a;
		else
			sum += a + b;
		if (sum >= z) {
			target = i;
			break;
		}
	}

	for (int i = 1; i <= target; i++) {
		if ((y % 4 == 0 && y % 100 != 0) || y % 400 == 0)
			days[2] = 29;
		else
			days[2] = 28;
		d++;
		if (d > days[m]) {
			d = 1;
			m++;
			if (m > 12) {
				y++;
				m = 1;
			}
		}
	}
	printf("%lld-%lld-%lld", y, m, d);
	return 0;
}
